﻿using System;
using System.Threading;

namespace Songhay
{
    /// <summary>
    /// Represents the results of an asynchronous navigation operation.
    /// </summary>
    /// <remarks>
    /// For more, see “Opening up Silverlight 4 Navigation: Introduction to INavigationContentLoader”
    /// [http://www.davidpoll.com/2009/11/30/opening-up-silverlight-4-navigation-introduction-to-inavigationcontentloader/]
    /// </remarks>
    public class NavigationContentLoaderAsyncResult : IAsyncResult
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="NavigationContentLoaderAsyncResult"/> class.
        /// </summary>
        /// <param name="asyncState">State of the async.</param>
        public NavigationContentLoaderAsyncResult(object asyncState)
        {
            this.AsyncState = asyncState;
            this.AsyncWaitHandle = new ManualResetEvent(true);
        }

        #region IAsyncResult Members

        /// <summary>
        /// Gets a user-defined object that qualifies or contains information about an asynchronous operation.
        /// </summary>
        /// <returns>A user-defined object that qualifies or contains information about an asynchronous operation.</returns>
        public object AsyncState { get; private set; }

        /// <summary>
        /// Gets a <see cref="T:System.Threading.WaitHandle"/> that is used to wait for an asynchronous operation to complete.
        /// </summary>
        /// <value></value>
        /// <returns>A wait handle that is used to wait for an asynchronous operation to complete.</returns>
        public WaitHandle AsyncWaitHandle { get; private set; }

        /// <summary>
        /// Gets a value that indicates whether the asynchronous operation completed synchronously.
        /// </summary>
        /// <returns>true if the asynchronous operation completed synchronously; otherwise, false.</returns>
        public virtual bool CompletedSynchronously
        {
            get { return true; }
        }

        /// <summary>
        /// Gets a value that indicates whether the asynchronous operation has completed.
        /// </summary>
        /// <returns>true if the operation is complete; otherwise, false.</returns>
        public virtual bool IsCompleted
        {
            get { return true; }
        }

        #endregion

        public object Result { get; set; }

    }
}
